﻿using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Media;
using Microsoft.Win32;

namespace Sub2EXO
{
	// Token: 0x02000003 RID: 3
	public partial class MainWindow : Window
	{
		// Token: 0x06000007 RID: 7 RVA: 0x000021FE File Offset: 0x000003FE
		public MainWindow()
		{
			this.InitializeComponent();
			this.InputBox_LostFocus(null, null);
			this.TemplateBox.Text = "[{i}]\nstart={start}\nend={end}\nlayer=1\noverlay=1\ncamera=0\n[{i}.0]\n_name=文本\n大小=34\n显示速度=0.0\n独立每个文字=0\n在路径上显示=0\n自动滚动=0\nB=0\nI=0\ntype=0\nautoadjust=0\nsoft=1\nmonospace=0\nalign=0\nspacing_x=0\nspacing_y=0\nprecision=1\ncolor=ffffff\ncolor2=000000\nfont=黑体\ntext={text}\n[{i}.1]\n_name=标准变换\nX=0.0\nY=0.0\nZ=0.0\n缩放率=100.00\n透明度=0.0\n旋转=0.00\nblend=0\n";
		}

		// Token: 0x06000008 RID: 8 RVA: 0x00002234 File Offset: 0x00000434
		private void GenerateBtn_Click(object sender, RoutedEventArgs e)
		{
			double num = double.Parse(this.fpsBox.Text);
			string text = this.TemplateBox.Text;
			this.OutputBox.Clear();
			this.OutputBox.AppendText("[exedit]\nwidth=1920\nheight=1080\nrate=60\nscale=1\nlength=0\naudio_rate=48000\naudio_ch=2\n");
			string input = this.InputBox.Text + "\n";
			MatchCollection matchCollection = Regex.Matches(input, "(?<sh>[0-9]+):(?<sm>[0-9]+):(?<ss>[0-9]+),(?<sms>[0-9]+).*-->.*(?<eh>[0-9]+):(?<em>[0-9]+):(?<es>[0-9]+),(?<ems>[0-9]+).*\n(?<c>.*)\n");
			Console.WriteLine("MatchCount: " + matchCollection.Count.ToString() + "\n");
			int num2 = 0;
			foreach (object obj in matchCollection)
			{
				Match match = (Match)obj;
				uint num3 = uint.Parse(match.Groups["sh"].Value);
				uint num4 = uint.Parse(match.Groups["sm"].Value);
				uint num5 = uint.Parse(match.Groups["ss"].Value);
				double num6 = uint.Parse(match.Groups["sms"].Value);
				uint num7 = uint.Parse(match.Groups["eh"].Value);
				uint num8 = uint.Parse(match.Groups["em"].Value);
				uint num9 = uint.Parse(match.Groups["es"].Value);
				double num10 = uint.Parse(match.Groups["ems"].Value);
				Console.WriteLine(string.Concat(new string[]
				{
					"Format Time: ",
					num3.ToString(),
					":",
					num4.ToString(),
					":",
					num5.ToString(),
					",",
					num6.ToString(),
					" - ",
					num7.ToString(),
					":",
					num8.ToString(),
					":",
					num9.ToString(),
					",",
					num10.ToString()
				}));
				double num11 = num3 * 3600U + num4 * 60U + num5 + num6 / 1000.0;
				double num12 = num7 * 3600U + num8 * 60U + num9 + num10 / 1000.0;
				Console.WriteLine("Time in second: " + num11.ToString() + " - " + num12.ToString());
				uint num13 = uint.Parse((Math.Floor(num11 * num) + 1.0).ToString());
				uint num14 = uint.Parse(Math.Floor(num12 * num).ToString());
				Console.WriteLine("Time in frame: " + num13.ToString() + " - " + num14.ToString());
				string text2 = match.Groups["c"].Value.TrimEnd(new char[]
				{
					'\r',
					'\n'
				});
				Console.WriteLine("Content: " + text2 + "\n");
				Encoding encoding = Encoding.GetEncoding("utf-16");
				byte[] bytes = encoding.GetBytes(text2);
				string text3 = "";
				foreach (byte b in bytes)
				{
					text3 += b.ToString("X2");
				}
				text3 = text3.PadRight(4096, '0');
				Console.WriteLine("ContentHex: " + text3 + "\n");
				string textData = text.Replace("{i}", num2.ToString()).Replace("{start}", num13.ToString()).Replace("{end}", num14.ToString()).Replace("{text}", text3);
				this.OutputBox.AppendText(textData);
				num2++;
			}
			SaveFileDialog saveFileDialog = new SaveFileDialog
			{
				Filter = "exo File|*.exo",
				FileName = "字幕",
				AddExtension = true
			};
			bool? flag = saveFileDialog.ShowDialog();
			bool flag2 = true;
			bool flag3 = flag.GetValueOrDefault() == flag2 & flag != null;
			if (flag3)
			{
				StreamWriter streamWriter = new StreamWriter(saveFileDialog.OpenFile(), Encoding.GetEncoding("GB2312"));
				streamWriter.Write(this.OutputBox.Text);
				streamWriter.Close();
			}
		}

		// Token: 0x06000009 RID: 9 RVA: 0x00002710 File Offset: 0x00000910
		private void InputBox_PreviewDragOver(object sender, DragEventArgs e)
		{
			bool dataPresent = e.Data.GetDataPresent(DataFormats.FileDrop);
			if (dataPresent)
			{
				e.Effects = DragDropEffects.Copy;
				e.Handled = true;
			}
		}

		// Token: 0x0600000A RID: 10 RVA: 0x00002744 File Offset: 0x00000944
		private void InputBox_PreviewDrop(object sender, DragEventArgs e)
		{
			this.InputBox.Focus();
			string path = ((Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
			StreamReader streamReader = new StreamReader(path);
			this.InputBox.Text = streamReader.ReadToEnd();
			streamReader.Close();
			e.Handled = true;
		}

		// Token: 0x0600000B RID: 11 RVA: 0x000027A8 File Offset: 0x000009A8
		private void InputBox_GotFocus(object sender, RoutedEventArgs e)
		{
			bool flag = this.InputBox.Text == this.alertText;
			if (flag)
			{
				this.InputBox.Clear();
				this.InputBox.Foreground = (Brush)new BrushConverter().ConvertFromString("#FF000000");
				this.InputBox.FontStyle = FontStyles.Normal;
			}
		}

		// Token: 0x0600000C RID: 12 RVA: 0x00002810 File Offset: 0x00000A10
		private void InputBox_LostFocus(object sender, RoutedEventArgs e)
		{
			bool flag = this.InputBox.Text == "";
			if (flag)
			{
				this.InputBox.Text = this.alertText;
				this.InputBox.Foreground = (Brush)new BrushConverter().ConvertFromString("#FF666666");
				this.InputBox.FontStyle = FontStyles.Italic;
			}
		}

		// Token: 0x04000001 RID: 1
		private string alertText = "输入SRT字幕脚本 或 拖入SRT文件";
	}
}
